/**
 *   This file is part of Graph-Tool.
 *
 *   Graph-Tool is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   Graph-Tool is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with Graph-Tool.  If not, see <http://www.gnu.org/licenses/>.
 */
package graphtool.graphs.algorithms.directed;

import graphtool.graphs.DirectedGraph;
import graphtool.graphs.GraphPropertyException;
import graphtool.math.matrices.IndexException;

import java.util.Collection;
import java.util.Iterator;

/**
 * @author a.lunkeit - alunkeit(at)gmail(dot)com
 *
 */
public class DirectedGraphPath<V, E> extends DirectedGraph<V, E>
{

  /**
   * The start node of the path
   */
  V _startNode;
  
  /**
   * Constructor
   */
  public DirectedGraphPath( V startNode )
  {
    this._startNode = startNode;
    
  }
  
  public V getStartNode()
  {
    return _startNode;
  }
  
  /**
   * Returns the next node in the path
   * 
   * @param node
   * @return
   */
  public V getNeighbourNode( V node ) throws GraphPropertyException
  {
    try
    {
      Collection<V> cv = this.neighbours( node );

      Iterator<V> i = cv.iterator();

      while( i.hasNext() )
      {
        V n = i.next();

        if( this.findEdge( node, n ) != null )
        {
          return n;
        }
      }

      return null;
    }
    catch( IndexException ie )
    {
      throw new GraphPropertyException( ie );
    }
  }
  
  public String toString()
  {
    return super.toString();
  }

}

